<?php

namespace App\Observers\Train;

use App\Models\Train\TrainTripInfo\TrainTripInfo;
use Illuminate\Support\Facades\Cache;

class TrainTripInfoObserver
{
    /**
     * Handle the User "created" event.
     *
     * @param TrainTripInfo $train_trip_info
     * @return void
     */
    public function created(TrainTripInfo $train_trip_info)
    {
        $cache_key = "Train:TripInfo:{$train_trip_info->train_code}:{$train_trip_info->from_station_code}:{$train_trip_info->to_station_code}";
        Cache::put($cache_key, $train_trip_info, config('trip.ttl.day'));
    }

    /**
     * Handle the User "updated" event.
     *
     * @param TrainTripInfo $train_trip_info
     * @return void
     */
    public function updated(TrainTripInfo $train_trip_info)
    {
        $cache_key = "Train:TripInfo:{$train_trip_info->train_code}:{$train_trip_info->from_station_code}:{$train_trip_info->to_station_code}";
        Cache::put($cache_key, $train_trip_info, config('trip.ttl.day'));
    }

    public function saved(TrainTripInfo $train_trip_info)
    {
        $cache_key = "Train:TripInfo:{$train_trip_info->train_code}:{$train_trip_info->from_station_code}:{$train_trip_info->to_station_code}";
        Cache::put($cache_key, $train_trip_info, config('trip.ttl.day'));
    }
}
